package com.group02.community.config;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ConverterKeyBuild;
import com.alibaba.excel.converters.DefaultConverterLoader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * 自定义Converter
 */
@Configuration
public class CustomConverterLoader {
    @Bean
    public DefaultConverterLoader defaultConverterLoader() {
        DefaultConverterLoader converters = new DefaultConverterLoader();
        EasyExcelLocalDateConverter localDateConverter = new EasyExcelLocalDateConverter();
        Map<ConverterKeyBuild.ConverterKey, Converter<?>> converterKeyConverterMap = converters.loadDefaultWriteConverter();
        converterKeyConverterMap.put(ConverterKeyBuild.buildKey(localDateConverter.supportJavaTypeKey()),localDateConverter);
        Map<ConverterKeyBuild.ConverterKey, Converter<?>> loadAllConverter = converters.loadAllConverter();
        loadAllConverter.put(ConverterKeyBuild.buildKey(localDateConverter.supportJavaTypeKey(),localDateConverter.supportExcelTypeKey()),localDateConverter);
        return converters;
    }
}
